import 'dart:async';
import 'dart:ui';

import 'package:fish_redux/fish_redux.dart';
import 'package:flutter_inapp_purchase/modules.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:www.znpigai.teacher/global_store/state.dart';

import 'item/state.dart';

class PayListState implements GlobalBaseState, Cloneable<PayListState> {
  bool isLoading = false; // 是否正在请求数据中

  List<PayState> items = <PayState>[];
  int pageIndex = GlobalState.firstPageIndex; // 页面索引
  int pageTotal = 1; // 页面总数

  /// purchase
  List<String> kProductIds = <String>[
    'S_A_WEEK',
    'S_A_MONTH',
    'S_A_QUARTER',
    'S_HALF_A_YEAR',
    'S_A_YEAR'
  ];
  List<String> notFoundIds = [];
  List<IAPItem> products = [];
  List<PurchaseDetails> purchases = [];
  List<String> consumables = [];
  bool isPurchaseAvailable = false;
  bool purchasePending = false;
  bool loadingPurchase = true;
  String queryProductError = '';
  PurchaseDetails purchaseDetails;
  String buttonText = '连接中，请稍候...';

  // StreamSubscription<List<PurchaseDetails>> subscription;
  StreamSubscription purchaseUpdatedSub;
  StreamSubscription purchaseErrorSub;

  PayListState();

  @override
  PayListState clone() {
    return PayListState()
      ..themeColor = themeColor
      ..userInfo = userInfo
      ..buttonText = buttonText
      ..items = items
      ..pageIndex = pageIndex
      ..pageTotal = pageTotal
      ..isLoading = isLoading
      ..purchaseUpdatedSub = purchaseUpdatedSub
      ..purchaseErrorSub = purchaseErrorSub
      ..notFoundIds = notFoundIds
      ..products = products
      ..purchases = purchases
      ..consumables = consumables
      ..isPurchaseAvailable = isPurchaseAvailable
      ..purchasePending = purchasePending
      ..loadingPurchase = loadingPurchase
      ..purchaseDetails = purchaseDetails
      ..kProductIds = kProductIds
      ..queryProductError = queryProductError;
  }

  @override
  Color themeColor;

  @override
  Map<String, dynamic> userInfo;
}

PayListState initState(Map<String, dynamic> args) {
  return PayListState();
}
